#region " LICENSE "
// DRILL - Dependency Resolution Interface Layer Library
// Copyright (c) 2008-2012 Wade A. Reynolds. All rights reserved.
// http://drill.codeplex.com/
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#endregion
using System.Collections.Generic;
using NUnit.Framework;

namespace Drill.Core.Utilities
{
    [TestFixture]
    public class StringToBooleanConverterTests
    {
        [Category("UnitTest")]
        [Test]
        [TestCaseSource("TestCasesForCanConvert")]
        public bool CanConvert(string value, bool defaultValue)
        {
            bool result = StringToBooleanConverter.Convert(value, defaultValue);
            return result;
        }

        public static IEnumerable<TestCaseData> TestCasesForCanConvert
        {
            get
            {
                yield return new TestCaseData(null, false).Returns(false);
                yield return new TestCaseData(null, true).Returns(true);
                yield return new TestCaseData("", false).Returns(false);
                yield return new TestCaseData("", true).Returns(true);
                yield return new TestCaseData(" ", false).Returns(false);
                yield return new TestCaseData(" ", true).Returns(true);

                yield return new TestCaseData("0", true).Returns(false);
                yield return new TestCaseData("f", true).Returns(false);
                yield return new TestCaseData("F", true).Returns(false);
                yield return new TestCaseData("false", true).Returns(false);
                yield return new TestCaseData("False", true).Returns(false);
                yield return new TestCaseData("fALSE", true).Returns(false);
                yield return new TestCaseData("FALSE", true).Returns(false);
                yield return new TestCaseData("n", true).Returns(false);
                yield return new TestCaseData("N", true).Returns(false);
                yield return new TestCaseData("no", true).Returns(false);
                yield return new TestCaseData("No", true).Returns(false);
                yield return new TestCaseData("NO", true).Returns(false);

                yield return new TestCaseData(" 0", true).Returns(false);
                yield return new TestCaseData(" f", true).Returns(false);
                yield return new TestCaseData(" F", true).Returns(false);
                yield return new TestCaseData(" false", true).Returns(false);
                yield return new TestCaseData(" False", true).Returns(false);
                yield return new TestCaseData(" fALSE", true).Returns(false);
                yield return new TestCaseData(" FALSE", true).Returns(false);
                yield return new TestCaseData(" n", true).Returns(false);
                yield return new TestCaseData(" N", true).Returns(false);
                yield return new TestCaseData(" no", true).Returns(false);
                yield return new TestCaseData(" No", true).Returns(false);
                yield return new TestCaseData(" NO", true).Returns(false);

                yield return new TestCaseData("0 ", true).Returns(false);
                yield return new TestCaseData("f ", true).Returns(false);
                yield return new TestCaseData("F ", true).Returns(false);
                yield return new TestCaseData("false ", true).Returns(false);
                yield return new TestCaseData("False ", true).Returns(false);
                yield return new TestCaseData("fALSE ", true).Returns(false);
                yield return new TestCaseData("FALSE ", true).Returns(false);
                yield return new TestCaseData("n ", true).Returns(false);
                yield return new TestCaseData("N ", true).Returns(false);
                yield return new TestCaseData("no ", true).Returns(false);
                yield return new TestCaseData("No ", true).Returns(false);
                yield return new TestCaseData("NO ", true).Returns(false);

                yield return new TestCaseData(" 0 ", true).Returns(false);
                yield return new TestCaseData(" f ", true).Returns(false);
                yield return new TestCaseData(" F ", true).Returns(false);
                yield return new TestCaseData(" false ", true).Returns(false);
                yield return new TestCaseData(" False ", true).Returns(false);
                yield return new TestCaseData(" fALSE ", true).Returns(false);
                yield return new TestCaseData(" FALSE ", true).Returns(false);
                yield return new TestCaseData(" n ", true).Returns(false);
                yield return new TestCaseData(" N ", true).Returns(false);
                yield return new TestCaseData(" no ", true).Returns(false);
                yield return new TestCaseData(" No ", true).Returns(false);
                yield return new TestCaseData(" NO ", true).Returns(false);
                
                yield return new TestCaseData("1", false).Returns(true);
                yield return new TestCaseData("t", false).Returns(true);
                yield return new TestCaseData("T", false).Returns(true);
                yield return new TestCaseData("true", false).Returns(true);
                yield return new TestCaseData("True", false).Returns(true);
                yield return new TestCaseData("TRUE", false).Returns(true);
                yield return new TestCaseData("y", false).Returns(true);
                yield return new TestCaseData("Y", false).Returns(true);
                yield return new TestCaseData("yes", false).Returns(true);
                yield return new TestCaseData("Yes", false).Returns(true);
                yield return new TestCaseData("YES", false).Returns(true);

                yield return new TestCaseData(" 1", false).Returns(true);
                yield return new TestCaseData(" t", false).Returns(true);
                yield return new TestCaseData(" T", false).Returns(true);
                yield return new TestCaseData(" true", false).Returns(true);
                yield return new TestCaseData(" True", false).Returns(true);
                yield return new TestCaseData(" TRUE", false).Returns(true);
                yield return new TestCaseData(" y", false).Returns(true);
                yield return new TestCaseData(" Y", false).Returns(true);
                yield return new TestCaseData(" yes", false).Returns(true);
                yield return new TestCaseData(" Yes", false).Returns(true);
                yield return new TestCaseData(" YES", false).Returns(true);

                yield return new TestCaseData("1 ", false).Returns(true);
                yield return new TestCaseData("t ", false).Returns(true);
                yield return new TestCaseData("T ", false).Returns(true);
                yield return new TestCaseData("true ", false).Returns(true);
                yield return new TestCaseData("True ", false).Returns(true);
                yield return new TestCaseData("TRUE ", false).Returns(true);
                yield return new TestCaseData("y ", false).Returns(true);
                yield return new TestCaseData("Y ", false).Returns(true);
                yield return new TestCaseData("yes ", false).Returns(true);
                yield return new TestCaseData("Yes ", false).Returns(true);
                yield return new TestCaseData("YES ", false).Returns(true);

                yield return new TestCaseData(" 1 ", false).Returns(true);
                yield return new TestCaseData(" t ", false).Returns(true);
                yield return new TestCaseData(" T ", false).Returns(true);
                yield return new TestCaseData(" true ", false).Returns(true);
                yield return new TestCaseData(" True ", false).Returns(true);
                yield return new TestCaseData(" TRUE ", false).Returns(true);
                yield return new TestCaseData(" y ", false).Returns(true);
                yield return new TestCaseData(" Y ", false).Returns(true);
                yield return new TestCaseData(" yes ", false).Returns(true);
                yield return new TestCaseData(" Yes ", false).Returns(true);
                yield return new TestCaseData(" YES ", false).Returns(true);
            }
        }
    }
}